<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><s:text name="context.title"/></title><%@ include file="/common/meta.jsp"%>
<script type="text/javascript">
	var v = [];
	$(document).ready(function(){
		$("#inputForm").validate();
	var cache = {},
		lastXhr;
	var cache1 = {},
	lastXhr1;
	$( ".collegeName" ).autocomplete({
		minLength: 0,
		source: function( request, response ) {
			var term = request.term;
			if ( term in cache ) {
				response( cache[ term ] );
				return;
			}
			lastXhr = $.post( "${ctx}/auto-complate-college.action?d=" + new Date(), {filter_LIKES_collegeName:term}, function( data, status, xhr ) {
			//	cache[ term ] = data;
				if ( xhr === lastXhr ) {
					response( data );
				}
			},"json");
		},
		select:function(e,ui){
			_getTeacher(ui.item.value);
			}
	});
	});
//Ajax获取教师信息
function _getTeacher(obj){
	$("#toSelect").empty();
	$.post("group!getTeacher?d="+new Date(),{collegeName:obj},function(data){
		$.each(data,function(inx,o){
			$("#toSelect").append("<option value='"+o.id+"'>"+o.name+"</option>");
			});
		},"json");
	
}

function go(obj){
	var v;
	if(obj > 0){
		//碰到重复的时候，路过
		v = $("#toSelect").find("option[selected=true]");
		v.each(function(inx,o){
			var f = false;
			$("#selected").find("option").each(function(ix,j){
				if(o.value == j.value){
					f = true;
					return true;
				}
				});
			if(!f){
				$("#selected").append($(o));
			}
			});
	}else{
		v = $("#selected").find("option[selected=true]");
		v.each(function(inx,o){
			var f = false;
			$("#toSelect").find("option").each(function(ix,j){
				if(o.value == j.value){
					f = true;
					return true;
				}
				});
			if(f){
				$(o).remove();
			}else{
				$("#toSelect").append($(o));
			}
			});
	//	$("#toSelect").append($("#selected").find("option[selected=selected]"));
	}
}

function goAll(obj){
	if(obj > 0 ){
		//碰到重复的时候，路过
		v = $("#toSelect").find("option");
		v.each(function(inx,o){
			var f = false;
			$("#selected").find("option").each(function(ix,j){
				if(o.value == j.value){
					f = true;
					return true;
				}
				});
			if(!f){
				$("#selected").append($(o));
			}
			});
	//	$("#selected").append($("#toSelect").find("option"));
	}else{
		v = $("#selected").find("option");
		v.each(function(inx,o){
			var f = false;
			$("#toSelect").find("option").each(function(ix,j){
				if(o.value == j.value){
					f = true;
					return true;
				}
				});
			if(f){
				$(o).remove();
			}else{
				$("#toSelect").append($(o));
			}
			});
	//	$("#toSelect").append($("#selected").find("option"));
	}
}
</script>
</head>
<body>
<br/>
<p align="center"><s:actionmessage theme="mytheme" cssClass="actionMessage"/></p>

<form id="inputForm" action="group.action" method="post">
<s:token></s:token>
<input type="hidden" name="id" value="${team.id }"/>
<h1 class="title01"><img src="${ctx}/images/02_15.gif" width="45" height="42" class="fl"/>成员管理</h1>
<fieldset class="fs_ys">
		<legend><s:if test="team.subTeam != null">小组名:</s:if><s:else>团队名:</s:else>${team.groupName }</legend>
	<h3></h3>
	<table>
		<tr>
			<td>学院<br/><input type="text" name="collegeName" class="collegeName" />&nbsp;</td>
			<td>&nbsp;</td>
			<td>已选&nbsp;</td>
		</tr>
		<tr>
			<td><p></p>
				<select id="toSelect" multiple="multiple" style="width: 150px;height: 280px"></select>
			&nbsp;</td>
			<td>
				<p><input type="button" value=" ->" onclick="go(1)"/></p><br/>
				<p><input type="button" value="=>" onclick="goAll(1)"/></p><br/><br/>
				<p><input type="button" value=" <-" onclick="go(-1);"/></p><br/>
				<p><input type="button" value="<=" onclick="goAll(-1)"/></p>
			&nbsp;</td>
			<td>
				<select id="selected" name="checkedTeachers" multiple="multiple" class="" style="width: 150px;height: 280px">
					<s:iterator value="team.teacherList" var="v">
						<option value="${v.id }">${v.teacherName }</option>
					</s:iterator>
				</select>
			&nbsp;</td>
		</tr>
	</table>
<p align="center"><input type="submit" onclick='$("#selected").find("option").attr("selected","selected")' value="  提 交" name="method:memberSave"/>  <input type="reset" onclick="history.back();" value="  取 消" /></p>
</fieldset>
</form>
</body>


</html>